package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter@Getter@
JsonIgnoreProperties("handler")
public class Travel extends BaseDomain{

    public static final Integer STATE_REFUSE = -1; //拒绝
    public static final Integer STATE_TEMP = 0; //草稿
    public static final Integer STATE_WAIT = 1; //待审核
    public static final Integer STATE_RELEASE = 2; //审核通过

    public static final Integer COLLECT_TEMP = 0; //未收藏
    public static final Integer COLLECT_RELEASE = 1; //已经收藏

    private String title;

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;

    private String perExpends;

    private Integer days;

    private Integer person = 2;

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date releaseTime;

    private Boolean isPublic = false;

    private String coverUrl;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date lastUpdateTime;

    private Integer state=STATE_TEMP;

    private User author;

    private Region place;

    private Integer collect = COLLECT_TEMP;      //收藏状态：是否收藏

    private Integer countCollect;

    private TravelContent travelContent;

    private Integer number;//游记点赞数量

    public String getStateName(){
        String msg = "拒绝";
        if(state == STATE_TEMP){
            msg = "草稿";
        }else if(state == STATE_WAIT){
            msg = "待审核";
        }else if(state == STATE_RELEASE){
            msg = "审核通过";
        }
        return msg;
    }

    public String getPersonValue(){
        String msg = "一个人的旅行";
        if(person == 2){
            msg = "和父母";
        }else if(person == 3){
            msg = "和朋友";
        }else if(person == 4){
            msg = "和同事";
        }else if(person == 5){
            msg = "和爱人";
        }else if(person == 6){
            msg = "和驴友";
        }
        return msg;
    }

    public String getCollectName(){
        String msg = "未收藏";
        if (collect == COLLECT_RELEASE){
            msg = "已经收藏";
        }
        return msg;
    }

    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        return JSONUtil.toJSONString(map);
    }


    /*赞的数量*/
    private  Integer praiseNum;
}